package com.atguigu.jxc.controller;

import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/supplier")
@RestController
public class SupplierContoller {
    @Autowired
    SupplierService supplierService;
    @PostMapping("/list")
    private Map<String,Object> list(Integer page,Integer rows,String supplierName){
      List<Supplier> suppliers = supplierService.list(page-1,rows,supplierName);
      Map<String,Object> map = new HashMap<>();
        map.put("rows",suppliers);
        return map;
    }
    @PostMapping("/save")
    private void save(Supplier supplier){
        supplierService.save(supplier);
    }
    //请求URL：http://localhost:8080/supplier/delete
    @PostMapping("delete")
    private void delect(@RequestParam String ids){
        List<String>list = Arrays.asList(ids.split(","));

        supplierService.delete(list);
    }
}
